package start.demo01.datatype.json.entity.editor.stringEditor;

import start.demo01.datatype.json.interfaces.StringEditor;

public class Replace extends StringEditor {

    private String regex;
    private String replacement;

    //$key replace(regex,replacement)
    public Replace(String name,String cmd) {
        super(name,cmd);
        int i = args.indexOf(',');
        this.regex = args.substring(0,i);
        this.replacement = args.substring(i+1);
    }

    @Override
    public void editor() {
        String origin=(String)map.get(name);
        origin=origin.replaceAll(regex,replacement);
        map.replace(name,origin);
    }

}
